﻿using System;
using System.Windows.Input;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;


// TODO: fetch these SearchProperties from the UIMap in the Database, based on strName
// TODO: use SearchProperties for initial searching, and FilterProperties to distinguish between search results if needed.
// TODO: instead of sending in searchLimitContainer, get it from the UIMap in the Database, and create it recursively:
//   new button() should first create an obect UIWindow, then the underlying UIWindow.
// TODO: add assertions for objects that are not found.

namespace SDWorx.ICTCorp.TestAutomationFramework.WinFormsApplication
{
    public class TAF_WinWindow : WinWindow
    {

        // Top level window
        public TAF_WinWindow(string strName, string strClass, string strTitle, string strAccessableName)
        {
            if (strName != "") this.SearchProperties[WinWindow.PropertyNames.Name] = strName;
            if (strClass != "") this.SearchProperties[WinWindow.PropertyNames.ClassName] = strClass;
            if (strAccessableName != "") this.SearchProperties[WinWindow.PropertyNames.AccessibleName] = strAccessableName;

            if (strTitle != "") this.WindowTitles.Add(strTitle);
        }

        // underlying window
        public TAF_WinWindow(UITestControl searchLimitContainer) :
            base(searchLimitContainer)
        {
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    public class TAF_WinButton : WinButton
    {
        public TAF_WinButton(UITestControl searchLimitContainer, String strName) :
            base(searchLimitContainer)
        {
            if (strName != "") this.SearchProperties[WinButton.PropertyNames.Name] = strName;
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    public class TAF_WinEdit : WinEdit
    {
        public TAF_WinEdit(UITestControl searchLimitContainer, String strName) :
            base(searchLimitContainer)
        {
            if (strName != "") this.SearchProperties[WinEdit.PropertyNames.Name] = strName;
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    public class TAF_WinComboBox : WinComboBox
    {
        public TAF_WinComboBox(UITestControl searchLimitContainer, String strName) :
            base(searchLimitContainer)
        {
            if (strName != "") this.SearchProperties[WinComboBox.PropertyNames.Name] = strName;
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }


    public class TAF_WinTitleBar : WinTitleBar
    {
        public TAF_WinTitleBar(UITestControl searchLimitContainer) :
            base(searchLimitContainer)
        {
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    public class TAF_WinMenu : WinMenu
    {

        public TAF_WinMenu(UITestControl searchLimitContainer) :
            base(searchLimitContainer)
        {
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    public class TAF_WinMenuItem : WinMenuItem
    {
        public TAF_WinMenuItem(UITestControl searchLimitContainer, String strName) :
            base(searchLimitContainer)
        {
            if (strName != "") this.SearchProperties[WinMenuItem.PropertyNames.Name] = strName;
            // set the value to the same of the parent
            if (searchLimitContainer.WindowTitles.Count > 0) this.WindowTitles.Add(searchLimitContainer.WindowTitles[0]);
        }
    }

    //TODO: add more controls here
}
